package com.tianbo.service.imp;

import com.tianbo.mapper.RoleMapper;
import com.tianbo.model.Role;
import com.tianbo.model.RoleExample;
import com.tianbo.model.UsersExample;
import com.tianbo.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoleServiceImpl implements RoleService{

    @Autowired
    private RoleMapper roleMapper;

    public List<Role> selectByExample(RoleExample example){
        return  roleMapper.selectByExample(example);
    }

    public int insert(Role record){
       return roleMapper.insert(record);
    }

    public boolean checkRole(Role role){
        //调用mapper类中的selectByExample方法，如果传入类型为null，则表示无条件查找
        RoleExample example = new RoleExample();
        RoleExample.Criteria criteria = example.createCriteria();

        if (role.getRoleName()!=null){
            criteria.andRoleNameEqualTo(role.getRoleName());
        }
        int count = roleMapper.countByExample(example); //没加入分页前的搜索总数据数

        if (count>0){
            return true;
        }else {
            return false;
        }
    }
}
